//
//  InvestEventTabViewController.m
//  investevent
//
//  Created by jiangshao on 16/3/14.
//  Copyright © 2016年 com.scj.investevent. All rights reserved.
//

#import "InvestEventTabViewController.h"
#import "InvestEventViewController.h"

@interface InvestEventTabViewController ()

@end

@implementation InvestEventTabViewController

- (void)viewDidLoad {
    [super viewDidLoad];
        tabedSlideView.delegate=self;
        tabedSlideView.baseViewController = self;
        tabedSlideView.tabItemNormalColor = [UIColor grayColor];
        tabedSlideView.tabItemSelectedColor = themeColor;
        tabedSlideView.tabbarTrackColor = [UIColor colorWithRed:0.833 green:0.052 blue:0.130 alpha:1.000];
        tabedSlideView.tabbarBottomSpacing = 0.0;
        
        DLTabedbarItem *item1 = [DLTabedbarItem itemWithTitle:@"本月日历" image:[UIImage imageNamed:@"red"] selectedImage:[UIImage imageNamed:@"red"]];
        DLTabedbarItem *item2 = [DLTabedbarItem itemWithTitle:@"下月日历" image:[UIImage imageNamed:@"red"] selectedImage:[UIImage imageNamed:@"red"]];
        
        tabedSlideView.tabbarItems = @[item1, item2];
        [tabedSlideView buildTabbar];
        tabedSlideView.selectedIndex = 0;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)selectTab:(int )selectedIndex{
    //    NSLog(@"selectTab,%d",selectedIndex);
    tabedSlideView.selectedIndex = selectedIndex;
}


- (NSInteger)numberOfTabsInDLTabedSlideView:(DLTabedSlideView *)sender{
    return 2;
}
- (UIViewController *)DLTabedSlideView:(DLTabedSlideView *)sender controllerAt:(NSInteger)index{
    //    NSLog(@"dadadas,%ld--",(long)index);
    switch (index) {
        case 0:
        {
            InvestEventViewController *ctrl = [[InvestEventViewController alloc] init];
            ctrl.date=[NSDate currentDateStringWithFormat:@"yyyyMM"];
            return ctrl;
        }
        case 1:
        {
            InvestEventViewController *ctrl = [[InvestEventViewController alloc] init];
            NSDate *chosenDate = [self getPriousorLaterDateFromDate:[NSDate date] withMonth:1];
            NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
            [formatter setDateFormat:@"yyyyMM"];
            NSString *date = [formatter stringFromDate:chosenDate];
            ctrl.date=date;
            return ctrl;
        }
        default:
            return nil;
    }
    
}

-(NSDate *)getPriousorLaterDateFromDate:(NSDate *)date withMonth:(int)month

{
    
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    
    [comps setMonth:month];
    
    NSCalendar *calender = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    
    NSDate *mDate = [calender dateByAddingComponents:comps toDate:date options:0];
    
    return mDate;
    
}

-(void)viewWillAppear:(BOOL)animated{
    self.navigationItem.rightBarButtonItem=nil;
    [[NavService getNav] setNavigationBarHidden:YES];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
